home *** CD-ROM | disk | FTP | other *** search
- /*
- WASTE Demo Project:
- Dialog Utilities
-
- Copyright © 1993-1995 Marco Piovanelli
- All Rights Reserved
-
- C port by John C. Daub
- */
-
- #ifndef __DIALOGS__
- #include <Dialogs.h>
- #endif
-
- #ifndef __WEDEMOAPP__
- #include "WEDemoIntf.h"
- #endif
-
- // static variable for GetMyStandardDialogFilter
-
- static ModalFilterUPP sMyStandardDialogFilterProc;
-
-
- pascal Boolean MyStandardDialogFilter( DialogRef dialog, EventRecord *event, short *item )
- {
- GrafPtr savePort;
- ModalFilterUPP stdFilter = NULL;
- Boolean reply = false;
- OSErr err;
- Boolean handled = false;
-
- // set up the port
-
- GetPort( &savePort );
- SetGrafPortOfDialog( dialog );
-
- // intercept window events directed to widnows behind the dialog
-
- if ( ( event->what == updateEvt ) || ( event->what == activateEvt ) )
- {
- if ( (DialogRef)(event->message) != dialog )
- {
- DoWindowEvent( event );
- } // end if (DialogRef)whatEvent != dialog
-
- }
-
- // is the default item a pushbutton?
-
- if ( GetDialogItemType( dialog, GetDialogDefaultItem( dialog ) ) == kButtonDialogItem )
- {
- // yes, so tell the Dialog Manager to care about its outline
-
- err = SetDialogDefaultItem( dialog, GetDialogDefaultItem( dialog ));
- if ( err != noErr )
- ; // put error handling in here
- }
-
- // this is something not in the original WASTE Demo App, but in the work that I've done
- // on my own projects, I've found it useful and helpful.
-
- // let's also make sure the cancel button can be handled...now, the cancel button
- // should be dialog item #2. So, we get dialog item #2, check if it's a button.
- // if it fills these 2 criteria, it's cancel. Even if the default item and the
- // cancel item are the same, still let them both be set this way so whatever keyboard
- // keys sthe user presses will be handled properly
-
- // pass the number "2" to GetDialogItemType...don't check for the cancel item (cause tho
- // cancel is defined as 2, we're not looking for cancel, we're looking for dialog item #2
- // this is just more readable code.
-
- // remember, this assumes that your cancel item will be item #2 (or at least the item
- // that you want to use for cancelling is #2), and that there are at least 2 items in
- // the dialog to begin with!
-
- if ( GetDialogItemType( dialog, kStdCancelItemIndex ) == kButtonDialogItem )
- {
- err = SetDialogCancelItem( dialog, kStdCancelItemIndex );
- if ( err != noErr )
- ; // put error handling in here
- }
-
-
- // call the standard Dialog Manager filter procedure
-
-
- err = GetStdFilterProc( &stdFilter );
- if ( (err == noErr) && (!handled) )
- reply = CallModalFilterProc( stdFilter, dialog, event, item );
-
- // restore the port
- SetPort( savePort );
-
- return reply;
- }
-
-
- pascal ModalFilterUPP GetMyStandardDialogFilter( void )
- {
- if ( sMyStandardDialogFilterProc == NULL )
- sMyStandardDialogFilterProc = NewModalFilterProc(MyStandardDialogFilter);
-
- return sMyStandardDialogFilterProc;
- }
-
-
-
- short GetDialogItemType( DialogRef dialog, short item )
- {
- short itemType;
- Handle itemHandle;
- Rect itemRect;
-
- GetDialogItem( dialog, item, &itemType, &itemHandle, &itemRect );
-
- return itemType;
- }
-
-
- Handle GetDialogItemHandle( DialogRef dialog, short item )
- {
- short itemType;
- Handle itemHandle;
- Rect itemRect;
-
- GetDialogItem( dialog, item, &itemType, &itemHandle, &itemRect );
-
- return itemHandle;
- }
-
- void GetDialogItemRect( DialogRef dialog, short item, Rect *itemRect )
- {
- short itemType;
- Handle itemHandle;
-
- GetDialogItem( dialog, item, &itemType, &itemHandle, itemRect );
-
- return;
- }
-
-
- pascal void SetDialogItemProc( DialogRef dialog, short item, UserItemUPP proc )
- {
- short itemType;
- Handle itemHandle;
- Rect itemRect;
-
- GetDialogItem( dialog, item, &itemType, &itemHandle, &itemRect );
-
- if ( BAND( itemType, 0x007F) == userItem )
- SetDialogItem( dialog, item, itemType, (Handle)proc, &itemRect );
-
- return;
- }
-
-